from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class InitBrowser():
    #初始化driver
    def __init__(self,driver_path):
        self.web = webdriver.Chrome(driver_path)

    def open_url(self,url):
        self.web.get(url)

    # 检查元素是否存在或者是否可点击
    def wait_element_visible(self,locate):
        element = WebDriverWait(self.web,10).until(EC.visibility_of_element_located(locate))
        return element
    #判断元素是否可见，可见代表非隐藏，宽和高都不为0
    def visibility_element_located(self,locate):
        pass
    #判断某个元素是否可见并且是enable的
    def element_to_be_clickable(self,locate):
        pass
    #判断某个元素中的text是否包含预期的字符串
    def text_to_be_present_in_element(self,locaate):
        pass

    # 点击事件
    def click(self,locate):
        self.wait_element_visible(locate).click()

    #输入事件
    def send_keys(self,locate,message):
        self.wait_element_visible(locate).send_keys(message)

    #页面刷新
    def refresh(self):
        self.web.refresh()

    #获取页面标题
    def title(self):
        return self.web.title

    #获取当前页面源码
    def source(self):
        return self.web.page_source



